<!doctype html>
<html>
<head>
	<meta charset="utf-8"><meta name="format-detection" content="telephone=no">
	<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
	<title>机构</title>
	<link rel="stylesheet" type="text/css" href="../../lib/css/skin.css"/>
</head>
<body>
<div id="root">
	<div class="app_warp">
		<div class="app_head">
			<!--<span class="left back"></span>-->
			<span class="name">机构</span>
			<span class="right search"></span>
		</div>
		<div class="app_selmenu col2">
			<a href="javascript:;" id="classify" class="menu" tapmode onclick="menuClick('classify')">全部专业</a>
			<a href="javascript:;" id="area" class="menu" tapmode onclick="menuClick('area')">全部地区</a>
			<ul id="nav_submenu" class="app_sel_sub_menu animated fadeInDown"></ul>
		</div>
		<div class="app_main">

			<div class="space"></div>
			
			<div class="app_box">
				<div class="box_cont padding_box">
					<ul id="mechanism_list" class="list_item line_list biger clearfix">
						<li class="nocontent por animated fadeInUp" style="display: none">
							<img src="../../lib/img/noproducts.png" alt="">
							<div class="text">
								暂无相关机构
							</div>
						</li>
					</ul>
				</div>
			</div>

			<div class="loading_line">
				<a href="javascript:;" class="loading_more"></a>
			</div>

		</div>
	</div>
</div>

<script id="nav_area_template" type="text/html">
	<%for(var i in directly) { var _data_ = directly[i]%>
	<li class="area <%if(i==0){%>active<%}%>" dataid=<%:=_data_.id%> tapmode onclick="subMenuClick(this,'area')">
		<a href="javascript:;"><%:=_data_.name%><%if(i!=0){%>市<%}%></a>
	</li>
	<%}%>
	<%for(var i in province) { var _data_ = province[i]%>
	<li class="area" dataid=<%:=_data_.id%> tapmode onclick="subMenuClick(this,'area')">
		<a href="javascript:;"><%:=_data_.name%>省</a>
	</li>
	<%}%>
</script>
<script id="nav_classify_template" type="text/html">
	<%for(var i in data) { var _data_ = data[i]%>
	<li class="classify <%if(i==0){%>active<%}%>" dataid=<%:=_data_.id%> tapmode onclick="subMenuClick(this,'classify')">
		<a href="javascript:;"><%:=_data_.name%><%if(i!=0){%>专业<%}%></a>
	</li>
	<%}%>
</script>
<script id="mechanism_list_template" type="text/html">
	<%for(var i in data) {%>
	<%
		var _data_ = data[i],
			_thisClasses_ = '';
		for(var _i_ in _data_.classid){
			_thisClasses_+='classid_'+ _data_.classid[_i_]+' '
		}
		_thisClasses_ += 'areaid_'+_data_.areaid;
	%>
	<li class="<%=_thisClasses_%>" tapmode onclick="_$.getView('mechanism',<%:=_data_.id%>,this)" data_id="<%:=_data_.id%>">
		<img class="pic imgcache" src="<%:=img%>" data_src="<%:=_data_.cover%>" alt="">
		<span class="comname">
			<%:=_data_.name%>
		</span>
		<span class="intention">
			<%
				for(var j in _data_.classid) {
					var _classid_ = _data_.classid[j]
					if(j<2){ %>
						<%:getClassifyName=_classid_%>
					<%}else if(_data_.classid.length>2 && j==2){%>
						等...
					<% } %>
				<% } %>
			 / <%:getAreaName=_data_.areaid%>

		</span>
		<span class="intro">
			<%:subStr16=_data_.intro%>
		</span>
	</li>
	<%}%>
</script>

<script>
	var
		acData = [0, 0],
		hideMenu,
		subMenuClick,
		menuClick,

		//点击了加载更多的时候执行的方法
		loadmore = function (status) {
			if(status===true){
				$('#mechanism_list li:not(.nocontent)').remove();
			}else{
			}
			var lists = $('#mechanism_list li:not(.nocontent)'),
				loadbtn = $('.loading_line .loading_more');

			loadbtn.addClass('active');

			_$.ajax({
				interface: 'search',
				data: {
					tag: 'mechanism_list',
					number: lists.length,
					cnum: acData[0],
					s_province: acData[1]
				},
				call: function (data) {
					if (data.status === 200) {
						_$.template('mechanism_list_template', {
							'data': data.data,
							'img': _$.imgCache.default
						}, function (html) {
							$('#mechanism_list').append(html);
							_$.imgCache.load();
							if($('#mechanism_list li:not(.nocontent)').length===0){
								$('#mechanism_list li.nocontent').show();
								$('.loading_line .loading_more').removeClass('active').addClass('nomore').off('click');
								return;
							}
							_$.sleep(function () {
								loadbtn.removeClass('active');
							}, 500);
						})

					} else if (data.statusCode === 0) {
						api.toast({
							msg: data.msg
						})
						$('.loading_line .loading_more').removeClass('active');
					} else if(status===true){
						$('#mechanism_list li.nocontent').show();
						$('.loading_line .loading_more').removeClass('active').addClass('nomore').off('click');
					} else{
						$('.loading_line .loading_more').removeClass('active').addClass('nomore').off('click');
					}
				}
			})
		},

		appready = function () {

			//初始化分类中的专业部分
			_$.db.get({
				key: 'classify',
				call: function (data) {
					window.__classifyData__ = data;
					_$.template('nav_classify_template', {'data': data}, function (html) {
						$('#nav_submenu').append(html);
					})
				}
			})

			//初始化分类中的地区部分
			_$.db.get({
				key: 'area',
				call: function (data) {
					window.__areaData__ = data;
					_$.template('nav_area_template', data, function (html) {
						$('#nav_submenu').append(html);
					})
				}
			})

			$('#mechanism_list li:not(.nocontent)').remove();
			_$.db.get({
				key: 'mechanism_list',
				call: function (data) {
					_$.template('mechanism_list_template', {'data': data, 'img': _$.imgCache.default}, function (html) {
						$('#mechanism_list').append(html);
						_$.imgCache.load();
					})
					$('.loading_line .loading_more').on('click', function(){
						loadmore(false);
					});
				}
			})

			//初始化页面点击动作
			var act = 'active',
				menu = $('.menu'),
				subMenu = $('.app_sel_sub_menu');

			//隐藏菜单的动作
			hideMenu = function (s) {
				menu.removeClass(act);
				!s && subMenu.hide();
			}

			//主菜单的点击动作
			menuClick = function (name) {

				var btn = $('#' + name);
				if (!btn.hasClass(act)) {
					hideMenu(true);
					btn.addClass(act);
					subMenu.find('li').show().not('.' + name).hide();
					subMenu.show();
				} else {
					hideMenu();
				}

			}

			//子菜单的点击动作
			subMenuClick = function (obj, name) {

				var _self = $(obj),
					_id = _self.attr('dataid'),
					_list = $('#mechanism_list li').hide();

				subMenu.find('li.' + name).removeClass(act);
				$('#' + name).text(_self.addClass(act).text());

				//保存一下旧的acData
				var _oldAcData = acData[0]+'|'+acData[1];

				if (name !== 'area') {
					acData[0] = _id;
				} else {
					acData[1] = _id;
				}

				//这个地方要判断一下，新的acData和旧的acData是否完全相同.
				if ((acData[0] + '|' + acData[1]) !== _oldAcData) {
					loadmore(true);
					$('.loading_line .loading_more').on('click', function(){
						loadmore(false);
					}).removeClass('nomore');
				}else{
					loadmore(false);
				}
				hideMenu();
			}

		};
</script>
<script src="../../lib/js/config.js"></script>
<script src="../../lib/js/jquery.js"></script>
<script src="../../lib/js/common.js"></script>
</body>
</html>